package com.jzr.task.job.shiyan;

import com.jzr.task.db1.mapper.MyPrimaryMapper;
import com.jzr.task.db1.mapper.TDoctorMapper;
import com.jzr.task.db1.model.TDoctor;
import com.jzr.task.db2.mapper.ShiyanMapper;
import com.jzr.task.db2.model.ShiyanDoctor;
import com.jzr.task.job.BaseJob;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.List;

@Component("Shiyan.SyncDoctor")
public class ShiyanSyncDoctor extends BaseJob {
    @Autowired
    private ShiyanMapper shiyanMapper;

    @Autowired
    private MyPrimaryMapper primaryMapper;

    @Autowired
    private TDoctorMapper doctorMapper;

    @Override
    public void process() throws Exception {
        //同步医生
        List<ShiyanDoctor> list = shiyanMapper.getDoctorList();
        for(ShiyanDoctor p : list){
            TDoctor doctor = new TDoctor();
            BeanUtils.copyProperties(p,doctor);
            doctor.setUpdateTime(LocalDateTime.now());
            Integer id = primaryMapper.getDoctorId(p.getCode());
            if(id == null){
                doctorMapper.insert(doctor);
            }else{
                doctor.setId(id);
                doctorMapper.updateById(doctor);
            }
        }
    }
}